﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Connect
{
     partial class ApplyIP : Form
    {
        int X = 0;
        int Y = 0;
        public ApplyIP()
        {
            InitializeComponent();
        }

        private void ApplyIP_Load(object sender, EventArgs e)
        {
            /*The Screen.GetWorkingArea(control) will provide you the working
                        area of a screen without the system tray area. The working area 
                        depends on the resolution of your monitor*/

            X = Screen.GetWorkingArea(this).Width; // This line gives the width of working area
            Y = Screen.GetWorkingArea(this).Height; // This line gives the width of working area			
            this.Location = new Point(X - this.Width, Y + this.Height); // This line sets the initial location of the form

            timer1.Enabled = true;
            timer1.Start();   // We'll start the timer which handles the opening of form.
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            /* The logic is that, first we will open the form below
			   taskbar at specified location and then in Timer's TICK event 
			   we'll just bring the form above taskbar to have the animated 
			   effect.
			  */
            int i = this.Location.Y; // First we will know form's Y-axis location
            // which will act as upper limit for form's location
            if (i > Y - this.Height)
            {
                this.Location = new Point(X - this.Width, i - 8);	// Here we just change the location
                // of form by 8 pixels(i-8)
            }
            else   // else we stop Timer1 and start Timer3 which holds the form for some time
            {
                timer1.Stop();
                timer1.Enabled = false;

                timer3.Start();
                timer3.Enabled = true;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            /*
			   Here the logic is same as opening the form, only location value of Y-axis
			   is increased, so that form slowly hides behind Task Bar.
			 */
            timer3.Stop();
            timer3.Enabled = false;

            int i = this.Location.Y;
            if (i < Y)
            {
                this.Location = new Point(X - this.Width, i + 8);
            }
            else
            {
                timer2.Stop();
                timer2.Enabled = false;
                this.Close();
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            timer2.Start();          // Here we start Timer2 which handles closing of form
            timer2.Enabled = true;
        }


        internal void ApplySetting(Profile profile)
        {
            // Invole the profile manager to apply the profile
            ProfileManager manager = new ProfileManager(profile);
            manager.OnStatusUpdate += new StatusUpdate(manager_OnStatusUpdate);
            manager.Run();
        }

        /// <summary>
        /// Callback function for ProfileManager to show messages
        /// </summary>
        /// <param name="message"></param>
        private void manager_OnStatusUpdate(string message)
        {
            txtStatus.AppendText(message);
        }




    }
}
